<?php


/**
 * 
 * Enter description here ...
 * @author vis
 *
 */
class ProjectsController extends EW_Core_Controller {
    
    /**
     * 
     * Enter description here ...
     */
    private function _initGlobals() {
        $this->view->projects = Doctrine_Core::getTable('Model_Project')->findAll();
        
        // Put a string into the leftSideBarVariable
        $this->_helper->layout()->formProject = new Application_Form_Projects(array(), $this, new Model_Project());

        /*
         * Adding Layout Variables by different ways
         */
        //Render contents of leftsidebar.phtml
        //$this->render('index', 'leftSideBar', FALSE);
    }
    
    /**
     * (non-PHPdoc)
     * @see EW_Core_Controller::_initialize()
     */
    protected function _initialize() {
        $front = Zend_Controller_Front::getInstance();
        $bootstrap = $front->getParam('bootstrap');
        
        $this->_initGlobals();
    }
    //==================================================================================================
    
    /**
     * 
     * 
     */
    function indexAction() {
        /* Access Application Config
        //Variant 1
        //$options = $this->getFrontController()->getParam('bootstrap')->getApplication()->getOptions();
        //echo '<pre>'; die(var_dump($options));
        
        // Variant 2
        $options = Zend_Registry::get('config');
        echo '<pre>'; die(var_dump($options->toArray()));
        */
        
        //$testCases = TestCases::find('all');
        //die(print_r($testCases));
    }
    //=================================================================================
    
    /**
     * 
     * Enter description here ...
     */
    function editprojectAction() {
        $projectId = $this->_getParam('id');
        $oProject = Doctrine_Core::getTable('Model_Project')->find($projectId);
        //Zend_Debug::dump($oProject); die();
        
        if($this->_request->isPost()) {
            
        }
        
        $this->view->formVirtualHost = new Application_Form_VirtualHost(array(), $this);
        
        $this->view->formTestCase = new Application_Form_TestCase(array(), $this, new Model_TestCase());
    }
    //=================================================================================
    
    /**
     * 
     * Enter description here ...
     */
    function addtestcaseAction() {
        $this->_helper->layout()->formProject = new Application_Form_TestCase(array(), $this, new TestCase());
    }
    //================================================================================
    
    public function deleteAction() {
        try {
            $q = Doctrine_Query::create()
                ->delete('Model_Project')
                ->addWhere('id = ?', $this->_getParam('id'));

            $numDeleted = $q->execute();
        }
        catch(Exception $e) {
            die($e->getMessage());
        }
        
        $this->_redirect('/projects');
        
        
    }
    
    /**
     * Action Method about EditVirtualHost
     */
    public function editvirtualhostAction()
    {
        $projectId = $this->_getParam('id');
        $oProject = Doctrine_Core::getTable('Model_Project')->find($projectId);
        //Zend_Debug::dump($oProject); die();
        
        $this->view->formTestCase = new Application_Form_VirtualHost(array(), $this, new Model_VirtualHost());
    }
    
}

